package com.sdf.com.mvp_rx_retraft;

import android.Manifest;
import android.support.annotation.NonNull;
import android.widget.Button;

import com.orhanobut.logger.Logger;
import com.sdf.com.mvp_rx_retraft.basePresenter.ActivityPresenter;
import com.sdf.com.mvp_rx_retraft.delegate.MainActivityDelegate;
import com.sdf.com.mvp_rx_retraft.utils.MPermission;
import com.sdf.com.mvp_rx_retraft.utils.permissiont.PermissionFail;
import com.sdf.com.mvp_rx_retraft.utils.permissiont.PermissionOK;

import butterknife.Bind;
import butterknife.OnClick;


public class MainActivity extends ActivityPresenter<MainActivityDelegate> {
    @Bind(R.id.bt_open_ca)
    Button btOpenCa;

    @OnClick(R.id.bt_open_ca)
    void onClick() {
        Logger.i("点击了");
        MPermission.with(this)
                .setPermission(Manifest.permission.READ_EXTERNAL_STORAGE
                        , Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .requestPermission();
//        MainActivityPermissionsDispatcher.callPhoneWithCheck(this);
//        MainActivityPermissionsDispatcher.showToastWithCheck(MainActivity.this);
//        MainActivityPermissionsDispatcher.doACacheNeedsPermissionWithCheck(MainActivity.th);
//        Intent intent = new Intent();
//        PermissionsDispatcherActivityPermissionsDispatcher.startCallWithCheck(this);
//        MainActivityPermissionsDispatcher.startCameraWithCheck(this);
//        MainActivityPermissionsDispatcher.startLocationWithCheck(this);
//        intent.setAction("android.media.action.IMAGE_CAPTURE");
//        intent.addCategory("android.intent.category.DEFAULT");
//        startActivity(intent);
    }

    @Override
    protected Class<MainActivityDelegate> getDelegateClass() {
        return MainActivityDelegate.class;
    }

    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        MPermission.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
    }

    @PermissionOK
    private void valdateSuccess() {
        Logger.i("权限通过");
    }

    @PermissionFail
    public void validateFail() {
        Logger.i("没有相应的权限");
    }
}
